package treeDemo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

class TreeNode {

	private int Id;
	private int ParentId;
	private String name;
	private List<TreeNode> children = new ArrayList<>();

	public TreeNode() {
		super();
	}

	public TreeNode(int id, int parentId, String name) {
		Id = id;
		ParentId = parentId;
		this.name = name;
	}

	public int getId() {
		return Id;
	}

	public int getParentId() {
		return ParentId;
	}

	public String getName() {
		return name;
	}

	public List<TreeNode> getChildren() {
		return children;
	}

	@Override
	public String toString() {
		return "TreeNode [Id=" + Id + ", ParentId=" + ParentId + ", name=" + name + "]";
	}
	
	public Map<String,Object> nodeToJson(){
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("Id", this.getId());
		map.put("Pid", this.getParentId());
		map.put("name", this.getName());
		map.put("children", this.children);
		return map;
	}
	
	/**
	 * 将指定节点加入自己的子节点集合
	 * 
	 * @param node 指定要加入的节点
	 */
	public void addChild(TreeNode node) {
		children.add(node);
	}
}